package sis.ra.evaluation;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import sis.ra.utility.Utils;


public class evaluation {

	public static HashMap <String, Double> getGroundTruth()
	{
		HashMap <String, Double> gth=new HashMap <String, Double> ();
		String filepath="C:\\Documents and Settings\\I820753\\Desktop\\dataset\\testing company\\groundtruth.txt";
		String content=Utils.readFile(filepath);
//		System.out.println(content);
		String [] lines=content.split("\n");
		for (int i=0;i<lines.length;i++)
		{
			String term=lines[i].split("\t")[0]+"\t"+lines[i].split("\t")[1];
			Double score=Double.parseDouble(lines[i].split("\t")[2]);
	//		System.out.println(term+"=="+score);
			gth.put(term, score);
		}
		return gth;
	}
	public static void main(String[] args) {
		String filepath="C:\\Documents and Settings\\I820753\\Desktop\\dataset\\testing company\\";//Amazon.com_wiki.score1";
		String evaluatefile="_wiki.score0";
		HashMap <String, Double> gth= getGroundTruth();
		ArrayList<String> ranks=new ArrayList<String> ();
		File filepaths=new File(filepath);
		File[] files=filepaths.listFiles();
		for (int t=0;t<files.length;t++)
		{
			if (!files[t].toString().contains(evaluatefile)) continue;
			String content=Utils.readFile(files[t].toString());
	//		System.out.println(content);
		
			String [] lines=content.split("\n");
			Double dcg5=0.0;
			Double dcg10=0.0;
			Double dcg20=0.0;
			Double dcg30=0.0;
			Double dcg40=0.0;
			Double dcg50=0.0;
			Double dcg60=0.0;
			Double dcg70=0.0;
			Double dcg80=0.0;
			Double dcg90=0.0;
			Double dcg100=0.0;
			for (int i=0;i<lines.length;i++)
			{
				if (lines[i].length()<1) continue;
				String term=lines[i].split("\t")[0]+"\t"+lines[i].split("\t")[1];
			
				if (gth.containsKey(term))
				{
					Double s=gth.get(term)/i;
					if (i<5)
						dcg5=dcg5+s;
					if (i<10)
						dcg10=dcg10+s;
					if (i<20)
						dcg20=dcg20+s;
					if (i<30)
						dcg30=dcg30+s;
					if (i<40)
						dcg40=dcg40+s;
					if (i<50)
						dcg50=dcg50+s;
					if (i<60)
						dcg60=dcg60+s;
					if (i<70)
						dcg70=dcg70+s;
					if (i<80)
						dcg80=dcg80+s;
					if (i<90)
						dcg90=dcg90+s;
					if (i<100)
						dcg100=dcg100+s;
				}else
				{
		//			System.out.println(term);
				}
			}
			System.out.println(files[t].toString().substring(66).replace(evaluatefile, "")+"\t"+dcg5+"\t"+dcg10+"\t"+dcg20+"\t"+dcg30+"\t"+dcg40+"\t"+dcg50+"\t"+dcg60+"\t"+dcg70+"\t"+dcg80+"\t"+dcg90+"\t"+dcg100);
		}
	}
}
